package com.dlnu.shoping.shopping.common;

import com.google.gson.Gson;
import lombok.Data;

import javax.annotation.Resource;
@Data
public class Result<T> {
    public static  final Result SUCCESS = new Result(1,"success",null);
    public static final Result FAIL = new Result(0,"fail",null);

    private int code;//前台通过code来判断 操作是否成功 1成功0失败
    private String msg;//若成功 msg为success ，如果失败，讲出失败原因
    private T data;//后台查询到的数据

    public Result(int code,String msg,T data){
        this.code = code;
        this.msg = msg;
        this.data= data;
    }

    public Result(T data){
        this.code = 1;
        this.msg = "success";
        this.data=data;
    }
    public String toString(){
        return new Gson().toJson(this);
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }
}
